package org.bonorsoft.common.exception;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 处理token中的异常信息
 * author：WilliamYe
 * create_time: 2020-11-17 16:17
 *
 */
@Controller
public class FilterErrorController {
    /*@ResponseBody
    @RequestMapping("/filterError/{code}/{message}")
    public Map<String,Object> error(@PathVariable("code")Integer code, @PathVariable("message")String message){
        Map<String,Object> map = new HashMap<>();
        map.put("code",code);
        map.put("message",message);
        System.out.println(map);
        *//*if(CommonConstant.TOKEN_NULL.equals(e.getMessage())){
            //token为空处理
            log.info(CommonConstant.TOKEN_NULL);
        }else if(CommonConstant.TOKEN_FAILURE.equals(e.getMessage())){
            //Token失效，请重新登录!
            log.info(CommonConstant.TOKEN_FAILURE);
        }else if(CommonConstant.TOKEN_INVALID.equals(e.getMessage())){
            //token非法无效处理
            log.info(CommonConstant.TOKEN_INVALID);
        }else if(CommonConstant.USER_NO_EXIST.equals(e.getMessage())){
            //用户不存在处理
            log.info(CommonConstant.USER_NO_EXIST);
        }else if(CommonConstant.USER_NO_ACTIVE.equals(e.getMessage())){
            //账号未激活处理
            log.info(CommonConstant.USER_NO_ACTIVE);
        }else {
            log.info("未知错误");
        }*//*
        return map;
    }*/

    @RequestMapping("/filterError/{code}/{message}")
    public String error(@PathVariable("code")Integer code, @PathVariable("message")String message){
        ModelMap map = new ModelMap();
        map.put("code",code);
        map.put("message",message);
        /*if(CommonConstant.TOKEN_NULL.equals(e.getMessage())){
            //token为空处理
            log.info(CommonConstant.TOKEN_NULL);
        }else if(CommonConstant.TOKEN_FAILURE.equals(e.getMessage())){
            //Token失效，请重新登录!
            log.info(CommonConstant.TOKEN_FAILURE);
        }else if(CommonConstant.TOKEN_INVALID.equals(e.getMessage())){
            //token非法无效处理
            log.info(CommonConstant.TOKEN_INVALID);
        }else if(CommonConstant.USER_NO_EXIST.equals(e.getMessage())){
            //用户不存在处理
            log.info(CommonConstant.USER_NO_EXIST);
        }else if(CommonConstant.USER_NO_ACTIVE.equals(e.getMessage())){
            //账号未激活处理
            log.info(CommonConstant.USER_NO_ACTIVE);
        }else {
            log.info("未知错误");
        }*/
        return "errorFilter/500";
    }
}
